Imports ValidationFramework
Imports ValidationFramework.Web.ASP
Imports QSBusinessLayerVB
Imports System


Partial Public Class GridViewUpdatingForm
  Inherits Page
  ' Methods
  Private Sub CreateValidations()
    If (personGridView.EditIndex > -1) Then
      Dim row As GridViewRow = personGridView.Rows.Item(personGridView.EditIndex)
            Helper.AddValidation(validatorGenerator.GetValidatorGenerator(), New FindControl(AddressOf row.FindControl))
    End If
  End Sub

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    CreateValidations()
  End Sub

  Protected Sub personGridView_DataBound(ByVal sender As Object, ByVal e As EventArgs)
    CreateValidations()
  End Sub

  Protected Sub personGridView_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
    e.Cancel = Not MyBase.IsValid
  End Sub

  Protected Sub validatorGenerator_TargetObjectRequired(ByVal sender As Object, ByVal e As TargetObjectRequiredEventArgs)
    If (editingPerson Is Nothing) Then
      Dim row As GridViewRow = personGridView.Rows.Item(personGridView.EditIndex)
      editingPerson = Helper.GetPerson(New FindControl(AddressOf row.FindControl))
    End If
    e.TargetObject = editingPerson
  End Sub


  ' Fields
  Private editingPerson As Person
End Class


